home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / games / iffdecrunch / aga_iffdepack.s
Text File  |  1980-01-03  |  4KB  |  145 lines

  1. *******************************************************************************
  2. * NewIFFDepack(source,cmap_dest,bitmap_dest)           D0-D7/A0-A6 Trashed!
  3. * ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  4. *     This function will correctly convert an AGA IFF-ILBM picture from its 
  5. * standard IFF chunks (& byterun compressed forms) into a normal ILBM-Bitmap.
  6. * It is fully compatible with AGA depths, hence works for AGA Pictures & works
  7. * fully with standard IFF picture formats... And fully PC-Relative ofcourse :)
  8. *
  9. * $Inputs:    a0.l = <source> (ptr to "iff picture")
  10. *        a3.l = <dest>   (ptr to "colourmap buffer")
  11. *        a4.l = <dest>   (ptr to "bitmap buffer")
  12. *        a5.l = <dest>   (ptr to "iff header buffer")
  13. *
  14. * $Outputs:    d0.l = success  (0 = successful)
  15. *                (-1= failure, buffer was not an iff-ilbm)
  16. *******************************************************************************
  17. FindChunk    macro
  18.         movea.l    a0,a1
  19. \@.get_chunk:    cmpi.l    #\1,(a1)
  20.         beq.s    \@.got_chunk
  21.         addq.w    #2,a1
  22.         bra.s    \@.get_chunk
  23. \@.got_chunk:
  24.         endm
  25.  
  26.         rsreset
  27. bm.pixelwidth    rs.w    1            ;bitmap width  (pixels)
  28. bm.pixelheight    rs.w    1            ;bitmap height (pixels)
  29. bm.bytewidth    rs.w    1            ;bitmap width  (bytes)
  30. bm.depth    rs.b    1            ;bitmap depth  (usually 0-8)
  31. bm.iffpacked    rs.b    1            ;if picture was byterun packed
  32.         rsreset
  33.  
  34.  
  35.  
  36. ExampleTest:    lea    iff_picture,a0        ;<source> pic from dpaint,etc.
  37.         lea    Copper_cols(pc),a3    ;<dest> for colour palette..
  38.         lea    ilbm_buffer(pc),a4    ;<dest> for ilbm bitmap..
  39.         lea    iff_header(pc),a5    ;<dest> for ilbm informations..
  40.         bsr.b    _LVONewIFFDepack
  41.         rts
  42.  
  43.  
  44.         cnop    0,4
  45. _LVONewIFFDepack
  46.         cmpi.l    #'FORM',(a0)        ;is this picture really IFF?
  47.         bne.w    NotIFF            ;if not this ID its not iff...
  48.  
  49. *-------------- get picture bitmap info (from IFF-BMHD Bitmap Header)
  50.  
  51.         FindChunk "BMHD"
  52.         addq.l    #8,a1            ;skip chunk id & chunk size
  53.         move.w    (a1)+,d0        ;get pixel width
  54.         move.w    d0,bm.pixelwidth(a5)    ;save pixel width
  55.         asr.w    #3,d0            ;divide by 8 (to get bytewidth)
  56.         move.w    d0,bm.bytewidth(a5)    ;save byte width
  57.  
  58.         move.w    (a1)+,bm.pixelheight(a5);get pixel height
  59.         addq.l    #4,a1            ;skip unimportant flags
  60.         move.b    (a1)+,bm.depth(a5)    ;get picture`s depth
  61.         addq.l    #1,a1            ;skip unimportant flags
  62.         move.b    (a1)+,bm.iffpacked(a5)    ;get byte containing packstatus
  63.  
  64. *-------------- get picture colourmap info (from IFF-CMAP Colourmap Header)
  65.  
  66.         FindChunk "CMAP"
  67.         addq.w    #4,a1            ;skip chunk id
  68.         movea.l    (a1)+,a2        ;size of cmap chunk
  69.         adda.l    a1,a2            ;a2.l = end of cmap chunk..
  70.  
  71. .copycols:    move.b    (a1)+,(a3)+        ;copy colour/hue...
  72.         move.b    (a1)+,(a3)+
  73.         move.b    (a1)+,(a3)+
  74.         cmpa.l    a1,a2            ;keep extracting until all
  75.         bgt.s    .copycols        ;colours are copied
  76.  
  77. *-------------- now extract bitmap (from IFF-BODY picture body header)
  78.  
  79.         FindChunk "BODY"
  80.         addq.l    #4,a1            ;skip chunk id
  81.         movea.l    (a1)+,a2        ;get length of body chunk
  82.         adda.l    a1,a2            ;a2.l = end of body chunk...
  83.  
  84. *-------------- is this picture`s bitmap Byterun-Compressed?
  85.  
  86.         tst.b    bm.iffpacked(a5)    ;test if we need to unpack ilbm
  87.         bne.s    byterun_loop
  88.  
  89. *-------------- simply bytecopy the unpack ilbm...
  90.  
  91. byteloop    move.b    (a1)+,(a4)+        ;simply copy it byte-for-byte
  92.         cmpa.l    a1,a2            ;until whole picture is done...
  93.         bgt.s    byteloop
  94.         rts
  95.  
  96. *-------------- now we can byterun depack the ILBM buffer...
  97.  
  98.         cnop    0,4
  99. byterun_loop    move.b    (a1)+,d0    ;get byte
  100.         ext.w    d0
  101.         tst.b    d0
  102.         bpl.b    copybytes
  103.         cmpi.b    #128,d0
  104.         bne.b    byterun
  105.         cmpa.l    a1,a2        ;finished yet??
  106.         bgt.s    byterun_loop
  107.         moveq    #0,d0        ;return success (0)
  108.         rts
  109.  
  110.         cnop    0,4
  111. byterun        move.b    (a1)+,d2    ;get byte
  112.         move.w    d0,d7
  113.         neg.w    d7
  114. .literal    move.b    d2,(a4)+    ;save unpacked byte
  115.         dbra    d7,.literal
  116.         cmpa.l    a1,a2        ;finished yet??
  117.         bgt.s    byterun_loop
  118.         moveq    #0,d0        ;return success (0)
  119.         rts
  120.  
  121.         cnop    0,4
  122. copybytes:    move.w    d0,d7
  123. .bytecopy    move.b    (a1)+,(a4)+    ;save unpacked byte
  124.         dbra    d7,.bytecopy
  125.         cmpa.l    a1,a2        ;finished yet??
  126.         bgt.s    byterun_loop
  127.         moveq    #0,d0        ;return success (0)
  128.         rts
  129.  
  130. NotIFF        moveq    #-1,d0        ;return failure (-1)
  131.         rts
  132.  
  133. *************** storage for our variables..
  134.  
  135. iff_header:    ds.w    1        ;pixel width of bitmap (eg. 640)
  136. pixelheight    ds.w    1        ;pixel height of bitmap (eg. 256)
  137. bytewidth    ds.w    1        ;bitmap bytewidth (eg. 80)
  138. depth        ds.b    1        ;no.of bitplanes (picture depth, eg. 7)
  139. iffpacked    ds.b    1        ;1=byterun packed, 0=raw ilbm
  140.  
  141. Copper_cols    ds.w    384        ;storage for our colours..
  142. ilbm_buffer    ds.b    80*256*7    ;storage for our bitmap..
  143.  
  144. iff_picture:    incbin    tmp:backatro.iff    ;our iff picture...
  145.